/*
 * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
 *
 * SPDX-License-Identifier: Unlicense OR CC0-1.0
 */

#include <stdint.h>
#include <string.h>
#include <stdbool.h>
#include <stdio.h>
#include <inttypes.h>
#include "nvs.h"
#include "nvs_flash.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_log.h"
#include "esp_event.h"

#include "myBT.h"
#include "mySerial.h"
#include "myLEDC.h"
#include "myTimer.h"
#include "myWiFi.h"
#include "myTCP.h"
void app_main(void)
{
  esp_err_t ret = nvs_flash_init(); // Init nvs
  // 检查flash是否有无法识别的格式区，若有则擦除并重新 init
  if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND)
  {
    ESP_ERROR_CHECK(nvs_flash_erase());
    ESP_ERROR_CHECK(nvs_flash_init());
  }
  // LEDS initialize
  ledc_init();
  // Serials initialize
  serial0_init(); // tx-1  rx-3
  serial1_init(); // tx-17 rx-16
  // WiFi and TCP_Server initialize
  ESP_ERROR_CHECK(esp_event_loop_create_default());
  wifi_softap_init();
  TCP_server_init();
}
